<div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title">
        <li class="layui-this">数据动态</li>
    </ul>
    <div id="data_mic1" style="width: 1000px;height:400px;display:inline;"></div>
    <hr class="layui-bg-blue">
    <div id="data_mic2" style="width: 1000px;height:400px;display:inline;"></div>
    <hr class="layui-bg-blue">
    <div id="data_mic3" style="width: 1000px;height:400px;display:inline;"></div>
    <hr class="layui-bg-blue">
</div>
<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart1 = echarts.init(document.getElementById('data_mic1'));
    // 指定图表的配置项和数据
    function getDay(day){
        var today = new Date();
        var targetday_milliseconds=today.getTime() + 1000*60*60*24*day;
        today.setTime(targetday_milliseconds); //注意，这行是关键代码
        var tYear = today.getFullYear();
        var tMonth = today.getMonth();
        var tDate = today.getDate();
        tMonth = doHandleMonth(tMonth + 1);
        tDate = doHandleMonth(tDate);
        return tYear+"-"+tMonth+"-"+tDate;
    }
    function doHandleMonth(month){
        var m = month;
        if(month.toString().length == 1){
            m = "0" + month;
        }
        return m;
    }
    var last7day1 = getDay(0),last7day2 = getDay(-1),last7day3 = getDay(-2),last7day4 = getDay(-3),last7day5 = getDay(-4),last7day6 = getDay(-5),last7day7 = getDay(-6);
    axios.get('/user/7day/sums')
        .then(function (response) {
            var info = response.data.data;
            var option1 = {
                title: {
                    text: '最近一周用户总数变化量'
                },
                toolbox: {
                    feature: {
                        saveAsImage: {}
                    }
                },
                tooltip: {},
                legend: {
                    data:['用户总数']
                },
                xAxis: {
                    data: [last7day7,last7day6,last7day5,last7day4,last7day3,last7day2,last7day1]
                },
                yAxis: {},
                series: [{
                    name: '用户总数',
                    type: 'bar',
                    data: [info.sum_1,info.sum_2,info.sum_3,info.sum_4,info.sum_5,info.sum_6,info.sum_7]
                }]
            };
            // 使用刚指定的配置项和数据显示图表。
            myChart1.setOption(option1);
        })
        .catch(function (error) {
            console.log(error);
        });
</script>
<script type="text/javascript">
    var myChart2 = echarts.init(document.getElementById('data_mic2'));
    axios.get('/forum/post/postsums')
        .then(function (response) {
            var info = response.data.data;
            myChart2.setOption({
                title: {
                    text: '版块活跃量'
                },
                toolbox: {
                    feature: {
                        saveAsImage: {}
                    }
                },
                series: {
                    type: 'pie',
                    data: (function () {
                        var res = [];
                        for(var i=0;i<info.length;i++){
                            res.push({
                                name:info[i].forum_name,
                                value:info[i].forum_sums
                            });
                        }
                        return res;
                    })()
                }
            });
        })
        .catch(function (error) {
            console.log(error);
        });
</script>
<script>
    var myChart3 = echarts.init(document.getElementById('data_mic3'));
    function getDay1(day){
        var today = new Date();
        var targetday_milliseconds=today.getTime() + 1000*60*60*24*day;
        today.setTime(targetday_milliseconds); //注意，这行是关键代码
        var tYear = today.getFullYear();
        var tMonth = today.getMonth();
        var tDate = today.getDate();
        tMonth = doHandleMonth1(tMonth + 1);
        tDate = doHandleMonth1(tDate);
        return tYear+"-"+tMonth+"-"+tDate;
    }
    function doHandleMonth1(month){
        var m = month;
        if(month.toString().length == 1){
            m = "0" + month;
        }
        return m;
    }
    var phone7day1 = getDay1(0),phone7day2 = getDay1(-1),phone7day3 = getDay1(-2),phone7day4 = getDay1(-3),phone7day5 = getDay1(-4),phone7day6 = getDay1(-5),phone7day7 = getDay1(-6);
    axios.get('/user/7day/nums')
        .then(function (response) {
            var info_user = response.data.data;
            axios.get('/post/7day/nums')
                .then(function (response) {
                    var info_post = response.data.data;
                    option3 = {
                        title: {
                            text: '最近一周论坛数据增长量'
                        },
                        tooltip: {
                            trigger: 'axis'
                        },
                        legend: {
                            data:['用户增长量','帖子增长量']
                        },
                        grid: {
                            left: '3%',
                            right: '4%',
                            bottom: '3%',
                            containLabel: true
                        },
                        toolbox: {
                            feature: {
                                saveAsImage: {}
                            }
                        },
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: [phone7day7,phone7day6,phone7day5,phone7day4,phone7day3,phone7day2,phone7day1]
                        },
                        yAxis: {
                            type: 'value'
                        },
                        series: [
                            {
                                name:'用户增长量',
                                type:'line',
                                stack: '总量',
                                data:[info_user.sum_7, info_user.sum_6, info_user.sum_5, info_user.sum_4, info_user.sum_3, info_user.sum_2, info_user.sum_1]
                            },
                            {
                                name:'帖子增长量',
                                type:'line',
                                stack: '总量',
                                data:[info_post.sum_7, info_post.sum_6, info_post.sum_5, info_post.sum_4, info_post.sum_3, info_post.sum_2, info_post.sum_1]
                            }
                        ]
                    };
                    myChart3.setOption(option3);
                })
                .catch(function (error) {
                    console.log(error);
                });
        })
        .catch(function (error) {
            console.log(error);
        });
</script>
